' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.08.27.16.49]) on 2023.08.27 at 20:38 (Coordinated Universal Time)
' A QB64 program by bplus (found at https://friends-of-basic.freeforums.net/thread/265/psychedelic-star-swirl)
' Ported to BASIC Anywhere Machine by Charlie Veniot

_Title "Psychedelic Star Swirl bplus 2018-03-04"
' translated from
' Psychedelic Star Swirl.bas SmallBASIC 0.12.8 [B+=MGA] 2017-03-03
' Spiral Pearl Swirl 4 SB.bas  SmallBASIC 0.12.8 [B+=MGA] 2017-03-01
' from Spiral Pearl Swirl.bas for FreeBASIC [B+=MGA] 2017-02-28
' from SdlBasic 3d version 2017-02-28
' inspired by spiral Bang

Const xmax = 1200
Const ymax = 760
Screen _NewImage(xmax, ymax, 32)

DECLARE SUB star (x, y, rInner, rOuter, nPoints, angleOffset)
DECLARE SUB chColor ()
DECLARE FUNCTION RAD(dA)

Dim r, g, b, clr
'whatever screen size your device here is middle
cx = xmax / 2: cy = ymax / 2: r = Rnd: g = Rnd: b = Rnd: k$ = " "
While 1
    size = 1
    radius = .06
    angle = sangle
    Cls
    While radius < 800
        x = Cos(angle) * radius
        y = Sin(angle) * radius
        r2 = (x ^ 2 + y ^ 2) ^ .5
        size = 4 * r2 ^ .25
        For r = size To 1 Step -4
            'cc = 160 + 95 * radius/400 - r/size*120
            chColor
            star (cx + x, cy + y, r / 3, r * 1.6, 5, Rnd * 360)
        Next
        angle = angle - .4
        radius = radius + 1
    Wend
    _delay 0.1
    sangle = sangle + _Pi(1 / 18)
Wend

Sub star (x, y, rInner, rOuter, nPoints, angleOffset)
    ' x, y are same as for circle,
    ' rInner is center circle radius
    ' rOuter is the outer most point of star
    ' nPoints is the number of points,
    ' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
    ' this is to allow us to spin the polygon of n sides
    pAngle = RAD(360 / nPoints): radAngleOffset = RAD(angleOffset)
    x1 = x + rInner * Cos(radAngleOffset)
    y1 = y + rInner * Sin(radAngleOffset)
    For i = 0 To nPoints - 1
        x2 = x + rOuter * Cos(i * pAngle + radAngleOffset + .5 * pAngle)
        y2 = y + rOuter * Sin(i * pAngle + radAngleOffset + .5 * pAngle)
        x3 = x + rInner * Cos((i + 1) * pAngle + radAngleOffset)
        y3 = y + rInner * Sin((i + 1) * pAngle + radAngleOffset)
        Line (x1, y1)-(x2, y2)
        Line (x2, y2)-(x3, y3)
        x1 = x3: y1 = y3
    Next
End Sub

Sub chColor ()
    clr = clr + 1
    Color _RGB32(127 + 127 * Sin(r * clr), 127 + 127 * Sin(g * clr), 127 + 127 * Sin(b * clr))
    If clr > 100000 Then r = Rnd * Rnd: g = Rnd * Rnd: b = Rnd * Rnd: clr = 0
End Sub
Function RAD (dA)
    RAD = _Pi(dA / 180)
End Function